//扩展运算符 ...
//将数组或对象展开
let arr1 = [10,20,30]; //...arr1 ===> 10,20,30

//1、需求 合并两个数组
let arr2 = [1,2,3];
let arr3 = [4,5];
arr2.concat(arr3); //es5
//ES6
[...arr2,...arr3]

//练习1
let sum = (x,y)=>x+y;
const items = [10,20];
sum(...items);

//练习2
function fn(...value){
    console.log(value)
};
const args = [0,1];
fn(-1,...args,2,...[3]); 

//练习3
var a = [];
function f(x,...y){
    x.push(...y)
};
f(a,[1,2,3,4]);
console.log(a); //[[1,2,3,4]]


//在对象中运用
let o1 = {id:1};
let o2 = {name:'o2'};
//合并 {id:1,name:'o2'}
let o3 = {...o1,...o2};

let fn = ()=>123;
let o4 = {...o3,fn};
console.log(o4);


//扩展题
let array = [
    {id:1,name:'a'},
    {id:6,name:'a'},
    {id:3,name:'a'},
    {id:4,name:'a'},
    {id:2,name:'a'},
];
//求id的最大值
let maxId = Math.max(...array.map(v=>v.id));
console.log(maxId);
//分解步骤
//1、求最大值 Math.max(10,20,30)
//2、数组中的id转换为1,6,3,4,2
